<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ include file="/WEB-INF/public/head.jsp" %>
<!DOCTYPE html>
<html>

	<head>

		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">

		<title>会员钱包后台管理系统</title>
		<meta name="keywords" content="H+后台主题,后台bootstrap框架,会员中心主题,后台HTML,响应式后台">
		<meta name="description" content="H+是一个完全响应式，基于Bootstrap3最新版本开发的扁平化主题，她采用了主流的左右两栏式布局，使用了Html5+CSS3等现代技术">

		<link rel="shortcut icon" href="${system}/static/favicon.ico">
		<link href="${system}/static/css/bootstrap.min.css?v=3.3.6" rel="stylesheet">
		<link href="${system}/static/css/font-awesome.css?v=4.4.0" rel="stylesheet">
		<link href="${system}/static/css/animate.css" rel="stylesheet">
		<link href="${system}/static/css/style.css?v=4.1.0" rel="stylesheet">
        <link href="${system}/static/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">

	</head>

	<body class="gray-bg">
		<div class="wrapper wrapper-content animated fadeInRight">

			<div class="col-sm-12">
				<div class="ibox float-e-margins">
					<div class="ibox-title">
						<h5>添加账号</h5>
						<div class="ibox-tools">
							<a class="collapse-link">
								<i class="fa fa-chevron-up"></i>
							</a>
							<a class="close-link">
								<i class="fa fa-times"></i>
							</a>
						</div>
					</div>
					<div class="ibox-content">
						<div class="form-horizontal m-t" id="signupForm">
							<div class="form-group">
								<label class="col-sm-3 control-label">用户名：</label>
								<div class="col-sm-5">
									<input id="username" name="username" placeholder="请输入6-9位的用户名" class="form-control" type="text" aria-required="true" aria-invalid="true" class="error">
                                    <span id="username-error" style="color: red; display: none" class="help-block m-b-none"><i class="fa fa-times-circle"></i> 请按要求用户名</span>
                                </div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">密码：</label>
								<div class="col-sm-5">
									<input id="password" placeholder="请输入6-16位的密码,不允许使用除字母数字下划线的其它字符" name="password" class="form-control" type="password">
                                    <span id="password-error" style="color: red; display: none"><i class="fa fa-times-circle"></i>请按要求输入密码</span>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">确认密码：</label>
								<div class="col-sm-5">
									<input id="confirm_password" placeholder="请再次输入密码" name="confirm_password" class="form-control" type="password">
                                    <span id="confirm_password-error" style="color: red; display: none;" class="help-block m-b-none"><i class="fa fa-times-circle"></i> 请按要求再次输入密码</span>
                                    <span id="confirm_password-error2" style="color: red; display: none;" class="help-block m-b-none"><i class="fa fa-times-circle"></i> 两次密码输入不匹配,请重新输入</span>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">角色：</label>
								<div class="col-sm-5">
									<select id="role" class="form-control" name="">
										<c:forEach var="role" items="${roles}">
											<option value="${role.role_id}">${role.role_name}</option>
										</c:forEach>
									</select>
								</div>
							</div>
							<div class="form-group">
								<div class="col-sm-8 col-sm-offset-3">
									<button id="sub" class="btn btn-primary" type="submit">提交</button>
								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>

		</div>


        <script src="${system}/static/js/alert.js"></script>
		<!-- 全局js -->
		<script src="${system}/static/js/jquery.min.js?v=2.1.4"></script>
		<script src="${system}/static/js/bootstrap.min.js?v=3.3.6"></script>

		<!-- 自定义js -->
		<script src="${system}/static/js/content.js?v=1.0.0"></script>

		<!-- jQuery Validation plugin javascript-->
		<script src="${system}/static/js/plugins/validate/jquery.validate.min.js"></script>
		<script src="${system}/static//js/plugins/validate/messages_zh.min.js"></script>

		<script src="${system}/static/js/demo/form-validate-demo.js"></script>


	</body>
<script>
    $("#sub").click(function () {




        var username = $("#username").val();
        var password = $("#password").val();
        var confirm_password = $("#confirm_password").val();
        var role = $("#role").val();
        var numberReg=/^(\w){6,16}$/;
        var passwordReg = /^[\w_-]{6,16}$/;
        if (!numberReg.test(username)){
            $("#username-error").show();
            return;
        }
        $("#username-error").hide();
        if (!passwordReg.test(password)){
            $("#password-error").show();
            return;
        }
        $("#password-error").hide();
        if (!passwordReg.test(confirm_password)){
            $("#confirm_password-error").show();
            return;
        }
        $("#confirm_password-error").hide();
        if (password!=confirm_password){
            $("#confirm_password-error2").show();
            return;
        }
        $("#confirm_password-error2").hide();
        var data={"admin_number":username,"admin_password":hex_md5(confirm_password).toUpperCase(),"role_id":role};
        ajax("${system}/admin/registerAdmin.do",data,"text","post",true,function (data) {
            if (data=="success"){
                swal({
                    title: "注册成功",
                    text: "账号:"+username+",已经成功注册,现在可用于登录",
                    type: "success"
                });
            }else if (data=="exist") {
                swal("注册失败！", "因为账号:"+username+"已存在", "error");
            }else{
                swal("注册失败！", "注册账号:"+username+"时出现问题,请稍后再试", "error");
			}
        },function (error) {
            console.log(error);
            alert("错误");
        })
    });
</script>
</html>